
package com.javaclimb.filmbuy.dao;

import com.javaclimb.filmbuy.entity.OrderInfo;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * 订单信息dao层
 */
@Repository
public interface OrderInfoDao extends Mapper<OrderInfo> {
    /*查询某用户的所有订单*/
    List<OrderInfo> findByUserIdAndLevel(@Param("userId")Long userId, @Param("level")Integer level);

    /*根据主键获取订单*/
    OrderInfo findById(Long id);

    /*更新订单状态*/
    void changeStatus(@Param("id")Long id,@Param("Status")String status);

    /*总销售额*/
    Double totalPrice();

    /*分类总销售额*/
    @Select("select e.name, sum(e.price) as price from (select a.totalPrice as price,d.name as name from order_info as a\n" +
            "join order_goods_rel as b on a.id=b.orderId\n" +
            "join goods_info as c on b.goodsId=c.id\n" +
            "join type_info as d on c.typeId=d.id) as e\n" +
            "group by e.name")
    List<Map<String, Object>> getTypePrice();

    /*分类总销量*/
    @Select("select e.name, sum(e.count) as count from (select b.count as count,d.name as name from order_info as a\n" +
            "join order_goods_rel as b on a.id=b.orderId\n" +
            "join goods_info as c on b.goodsId=c.id\n" +
            "join type_info as d on c.typeId=d.id) as e\n" +
            "group by e.name")

    List<Map<String, Object>> getTypeCount();
}

